package com.web;

import lombok.Data;

/**
 * 统一返回类型
 */
@Data
public class Result {
    private int code;

    private String msg;

    private Object data;

    public Result(CodeEnum code, String msg, Object data){
        this.code = code.getCode();
        this.msg = msg;
        this.data = data;
    }

    public static Result success(String msg, Object data){
         return new Result(CodeEnum.SUCCESS, msg, data);
    }

    public static Result success(Object data){
        return new Result(CodeEnum.SUCCESS, CodeEnum.SUCCESS.getCodeName(), data);
    }

    public static Result success(){
        return new Result(CodeEnum.SUCCESS, CodeEnum.SUCCESS.getCodeName(), null);
    }

    public static Result failure(String msg, Object data){
        return new Result(CodeEnum.FAILURE, msg, data);
    }

    public static Result failure(Object data){
        return new Result(CodeEnum.FAILURE, CodeEnum.FAILURE.getCodeName(), data);
    }

    public static Result failure(){
        return new Result(CodeEnum.FAILURE, CodeEnum.FAILURE.getCodeName(), null);
    }


}
